package com.by.order.controller;

import com.by.order.api.service.IOrderService;
import com.by.order.api.vo.OrderVo;
import com.by.rpc.annotation.ApiEndpoint;
import com.by.rpc.annotation.RpcMethod;
import com.by.rpc.annotation.RpcParam;
import com.by.rpc.annotation.RpcPath;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * 订单RPC控制器
 * 专门用于处理来自网关的RPC调用
 */
@Service
@ApiEndpoint(serviceName = "order-service", version = "1.0.0", group = "default")
public class OrderRpcController {

    @Autowired
    @Qualifier("orderServiceImpl")
    private IOrderService orderService;

    @RpcMethod(value = "/order/seckill/create", method = "POST")
    public OrderVo seckillCreateOrder(@RpcParam("userId") Long userId,
                                      @RpcParam("goodsId") Long goodsId) {
        return orderService.seckillCreateOrder(userId, goodsId);
    }


    @RpcMethod(value = "/order/{id}", method = "GET")
    public OrderVo getOrderById(@RpcPath("id") Long id) {
        return orderService.getOrderById(id);
    }

    @RpcMethod(value = "/order/{id}/pay", method = "POST")
    public boolean payOrder(@RpcPath("id") Long id) {
        return orderService.payOrder(id);
    }

    @RpcMethod(value = "/order/{id}/cancel", method = "POST")
    public boolean cancelOrder(@RpcPath("id") Long id) {
        return orderService.cancelOrder(id);
    }
}